﻿using System;
using System.Configuration;
using System.Security.Policy;
using System.Web;

namespace FFIV.Lib.Utilities
{
	public static class UrlUtility
	{
		public static string Admin_AddArticle;

		public static string Admin_EditArticle;

		public static string Admin_ManageArticles;

		public static string Admin_ManageCategories;

		public static string Admin_RegisterUser;

		public static string Admin_ManageUser;

		public static string Admin_EditUserInfo;

		public static string Articles_Detail;

		public static string Articles_List;

		public static string Articles_Search;


		static UrlUtility()
		{
			try
			{
				Admin_AddArticle = ConfigurationManager.AppSettings["Admin_AddArticle"];
				Admin_EditArticle = ConfigurationManager.AppSettings["Admin_EditArticle"];
				Admin_ManageArticles = ConfigurationManager.AppSettings["Admin_ManageArticles"];
				Admin_ManageCategories = ConfigurationManager.AppSettings["Admin_ManageCategories"];
				Admin_RegisterUser = ConfigurationManager.AppSettings["Admin_RegisterUser"];
				Admin_ManageUser = ConfigurationManager.AppSettings["Admin_ManageUser"];
				Admin_EditUserInfo = ConfigurationManager.AppSettings["Admin_EditUserInfo"];

				Articles_Detail = ConfigurationManager.AppSettings["Articles_Detail"];
				Articles_List = ConfigurationManager.AppSettings["Articles_List"];
				Articles_Search = ConfigurationManager.AppSettings["Articles_Search"];
			}
			catch { }
		}

		public static string GetArticleDetailUrl(int articleId)
		{
			return string.Format("/Articles/{0}.html", articleId);
			//return string.Format("~/Articles/Detail.aspx?id={0}", articleId);
		}

		public static string GetCategoriesUrl(int categoryId)
		{
			return string.Format("~/Categories/{0}_0.html", categoryId);
			//return string.Format("{0}?id={1}", Articles_List, categoryId);
		}

		public static string GetCategoriesUrl(int categoryId, int pageId)
		{
			return string.Format("~/Categories/{0}_{1}.html", categoryId, pageId);
		}

		public static string GetPermissionErrorUrl()
		{
			return "~/statics/NoAccess.html";
		}

		public static string GetArticleEditUrl(int articleId)
		{
			return string.Format("~/Admin/EditArticle.aspx?id={0}", articleId);
		}

		public static string GetSearchUrl(string keywords)
		{
			//return HttpUtility.UrlEncode(string.Format("~/Search/{0}", keywords));
			return string.Format("~/Articles/Search.aspx?title={0}", HttpUtility.UrlEncode(keywords));
		}

		public static string GetSearchUrl(string keywords, int pageId)
		{
			//return HttpUtility.UrlEncode(string.Format("~/Search/{0}/{1}", keywords, pageId));
			return string.Format("~/Articles/Search.aspx?title={0}&page={1}", HttpUtility.UrlEncode(keywords), pageId);
		}
	}
}
